﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
namespace GameUnit
{
    public class Weapon : MonoBehaviour
    {
        public Unit Unit;
        Effect AttackEffect;
        public float Cycle;
        public string Name;
        public string PrefabPath;
        public long lastAttackTime = 0;
        public void Init(Hashtable weaponConfig,Unit unit)
        {
            this.Unit = unit;
            this.Cycle = (float)weaponConfig[":cycle"];
            this.Name = (string)weaponConfig[":name"];
            this.PrefabPath = (string)weaponConfig[";prefab"];
            if (weaponConfig.ContainsKey(":effect"))
            {
                string strEffectName = (string)weaponConfig[":effect"];
                this.AttackEffect = EffectManager.CreateEffect(strEffectName,this.Unit);
            }
        }

        public virtual void ExecAttack()
        {  
            GameScene curScene = Game.Scene.Cur<GameScene>();
            if (this.lastAttackTime + ((long)(this.Cycle * 1000000000)) < curScene.ServerTime)
            {
                this.Unit.CallEvent("WeaponStart.AttackStart", "");
                this.lastAttackTime = curScene.ServerTime;
                if (this.AttackEffect != null)
                {
                    this.AttackEffect.Exec();
                }
            }
        }
        

    }
}